package com.erp.controller.baseDataController;


import com.erp.pojo.MaterialCategory;
import com.erp.service.baseDataService.MaterialCateService;
import com.erp.utils.Msg;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLOutput;
import java.util.List;

@RestController
@RequestMapping("/Cate")
public class MaterialCateController {

    @Autowired
    private MaterialCateService materialCateService;

    @RequestMapping("/getCate")
    public Msg getCategory(
                            @RequestParam(name = "level",defaultValue = "1")short level,
                            @RequestParam(name = "page",defaultValue = "1")int page,
                           @RequestParam(name = "limit",defaultValue = "10")int limit){
        System.out.println(level);


        System.out.printf("进入控制器");
        Msg msg = new Msg();
        PageHelper.startPage(page, limit);

        List<MaterialCategory> list = materialCateService.select(level);

        PageInfo<MaterialCategory> pagelist = new PageInfo<>(list);



        msg.setCode(0);
        msg.setCount(pagelist.getTotal());
        msg.setMsg("");
        msg.setData(pagelist.getList());

        System.out.println(msg);

        return msg;

    }

}
